package com.ly.web.controller.monitor;

import java.util.List;

import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.core.page.TableDataInfo;
import com.ly.common.enums.BusinessType;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.system.domain.SysLogininfor;
import com.ly.system.service.ISysLogininforService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统访问记录
 * @author
 */
@RestController
@RequestMapping ("/monitor/logininfor")
public class SysLogininforController extends BaseController {

    @Resource
    private ISysLogininforService logininforService;

    @PreAuthorize ("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping ("/list")
    public TableDataInfo list (SysLogininfor logininfor) {
        startPage ();
        List<SysLogininfor> list = logininforService.selectLogininforList ( logininfor );
        return getDataTable ( list );
    }

    @Log (title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize ("@ss.hasPermi('monitor:logininfor:export')")
    @GetMapping ("/export")
    public AjaxResult export (SysLogininfor logininfor) {
        List<SysLogininfor> list = logininforService.selectLogininforList ( logininfor );
        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor> ( SysLogininfor.class );
        return util.exportExcel ( list, "登录日志" );
    }

    @PreAuthorize ("@ss.hasPermi('monitor:logininfor:remove')")
    @Log (title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{infoIds}")
    public AjaxResult remove (@PathVariable Long[] infoIds) {
        return toAjax ( logininforService.deleteLogininforByIds ( infoIds ) );
    }

    @PreAuthorize ("@ss.hasPermi('monitor:logininfor:remove')")
    @Log (title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping ("/clean")
    public AjaxResult clean () {
        logininforService.cleanLogininfor ();
        return AjaxResult.success ();
    }
}
